#!/usr/bin/env bash

# short script to package up Luminous into a zip and tar.bz2 archive,
# sans all the rubbish that people don't need (shell scripts, testing 
# scripts, etc).
# The packages are written to the parent directory.

# get the version number from the README
version=$( sed -r '1s/.*[\t ]//' README | head -n 1)
echo "Luminous version $version, is this correct? [y]es/[n]o/[q]uit"

read confirm
confirm=$(echo $confirm | tr '[A-Z]' '[a-z]')
if [ "${confirm[0]:0:1}" == "n" ]; then
  echo Enter version number:
  read version
elif [ "${confirm[0]:0:1}" != "y" ]; then
  exit 1   
fi

# zip wants each individual file specified,
# tar doesn't. It's a pain
excludes=(
          luminous/*.sh
          luminous/**/*~ 
          luminous/tests/*
          luminous/tests
          luminous/docs/*
          luminous/docs

          );

tar_ex=
zip_ex="-x"

for x in ${excludes[@]}
do
  tar_ex="$tar_ex --exclude=$x"
  zip_ex="$zip_ex $x"
done


cd ..
tar -cvvjf luminous-$version.tar.bz2 $tar_ex luminous/
zip -r luminous-$version.zip $tar_ex  luminous/

echo "Done"

